package androidx.core.app;

import android.app.Activity;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.SparseIntArray;
import android.view.FrameMetrics;
import android.view.Window;
import android.view.Window.OnFrameMetricsAvailableListener;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;

public class FrameMetricsAggregator {
    private a ˏ;

    @RestrictTo({d.LIBRARY_GROUP_PREFIX})
    @Retention(RetentionPolicy.SOURCE)
    public @interface MetricType {
    }

    static class a {
        a() {
        }
    }

    @RequiresApi(24)
    static class b extends a {
        private static Handler ʼ = null;
        private static HandlerThread ˎ = null;
        SparseIntArray[] ˊ = new SparseIntArray[9];
        private ArrayList<WeakReference<Activity>> ˋ = new ArrayList();
        OnFrameMetricsAvailableListener ˏ = new OnFrameMetricsAvailableListener(this) {
            final /* synthetic */ b ˎ;

            {
                this.ˎ = r1;
            }

            public void onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics, int i) {
                if ((this.ˎ.ॱ & 1) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[0], frameMetrics.getMetric(8));
                }
                if ((this.ˎ.ॱ & 2) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[1], frameMetrics.getMetric(1));
                }
                if ((this.ˎ.ॱ & 4) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[2], frameMetrics.getMetric(3));
                }
                if ((this.ˎ.ॱ & 8) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[3], frameMetrics.getMetric(4));
                }
                if ((this.ˎ.ॱ & 16) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[4], frameMetrics.getMetric(5));
                }
                if ((this.ˎ.ॱ & 64) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[6], frameMetrics.getMetric(7));
                }
                if ((this.ˎ.ॱ & 32) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[5], frameMetrics.getMetric(6));
                }
                if ((this.ˎ.ॱ & DnsConfig.MAX_CACHE_ENTRIES) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[7], frameMetrics.getMetric(0));
                }
                if ((this.ˎ.ॱ & 256) != 0) {
                    this.ˎ.ॱ(this.ˎ.ˊ[8], frameMetrics.getMetric(2));
                }
            }
        };
        int ॱ;

        b(int i) {
            this.ॱ = i;
        }

        void ॱ(SparseIntArray sparseIntArray, long j) {
            if (sparseIntArray != null) {
                int i = (int) ((500000 + j) / 1000000);
                if (j >= 0) {
                    sparseIntArray.put(i, sparseIntArray.get(i) + 1);
                }
            }
        }
    }

    public FrameMetricsAggregator() {
        this(1);
    }

    public FrameMetricsAggregator(int i) {
        if (VERSION.SDK_INT >= 24) {
            this.ˏ = new b(i);
        } else {
            this.ˏ = new a();
        }
    }
}
